package com.mc.mq.rocketmq.base.producer;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.util.concurrent.TimeUnit;

public class SyncProducer {
    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
        //实例化消息生产者Producer
        DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");
//        producer.setNamesrvAddr("192.168.43.218:9876;192.168.43.219:9876;");
        producer.setNamesrvAddr("192.168.3.31:9876;192.168.3.32:9876;");
        producer.start();
        for (int i = 0; i < 10; i++) {
            Message msg = new Message("springboot-mq", "Tag1", ("Hello World" + i).getBytes());
            SendResult result = producer.send(msg);
//            SendStatus status = result.getSendStatus();
            System.out.println(result);
            TimeUnit.SECONDS.sleep(1);
        }
        producer.shutdown();
    }
}
